import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { KitService } from './kit.service';
import { CreateKitDto } from './dto/create-kit.dto';
import { UpdateKitDto } from './dto/update-kit.dto';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import { EventPattern, MessagePattern, Payload } from '@nestjs/microservices';
import { QueryDto } from './dto/query.dto';


@Controller('kit')
export class KitController {
  constructor(private readonly kitService: KitService) {}

  @Post()
  @ApiOperation({
    summary: '创建kit',
    description: '创建kit',
  })
  @ApiResponse({
    status: 200,
    description: '创建成功',
    type: CreateKitDto,
  })
  @MessagePattern('createKit')
  create(createKitDto: CreateKitDto) {
    return this.kitService.create(createKitDto);
  }

  @Get()
  @ApiOperation({
    summary: '获取kit列表',
    description: '获取kit列表',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: [UpdateKitDto],
  })
  @MessagePattern('findAllKits')
  findAll(query: QueryDto) {
    return this.kitService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({
    summary: '获取kit详情',
    description: '获取kit详情',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: UpdateKitDto,
  })
  @MessagePattern('findOneKit')
  findOne(id: string) {
    return this.kitService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({
    summary: '更新kit',
    description: '更新kit',
  })
  @ApiResponse({
    status: 200,
    description: '更新成功',
    type: UpdateKitDto,
  })
  @MessagePattern('updateKit')
  update(@Payload('id') id: string, @Payload('updateKitDto') updateKitDto: UpdateKitDto) {
    return this.kitService.update(+id, updateKitDto);
  }

  @Delete(':id')
  @ApiOperation({
    summary: '删除kit',
    description: '删除kit',
  })
  @ApiResponse({
    status: 200,
    description: '删除成功',
    type: UpdateKitDto,
  })
  @MessagePattern('removeKit')
  remove(id: string) {
    return this.kitService.remove(+id);
  }
}
